package com.ten.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ten.pojo.User;
import com.ten.service.UserService;

@Controller
public class UserController {
  @Autowired
  private UserService userService;
  @RequestMapping("/toLogin")
  public String toLogin(String msg,HttpServletRequest request){
	  if("".equals("0")){
		  request.setAttribute("login", "您尚未登录，请先登录！");
	  }
	  return "login";
  }
  @RequestMapping(value="/login",method=RequestMethod.POST)
  public String login(String username,String password,HttpServletRequest request){
	  User u =userService.login(username, password);
	  if(u!=null){
		  request.getSession().setAttribute("user", u);
		  return "index";
	  }
	  return this.toLogin("0", request);
  }
  @RequestMapping("/")
  public String index(){
	  return "login";
  }
}
